<template>
	<div class="">
    <van-overlay :show="show" >
  <div class="wrapper" @click.stop>
  

		<div class="RedBox">
            <div class="topcontent">
                <h2 class="bounceInDown">恭喜你获得红包</h2>
                <span class="text flash"><b>{{total_amount}}</b>元</span>
                <div class="avatar" v-show="false">
                    <div id="open" ><img :src="user.avatar" alt="" width="80" height="80" class="zoomIn"></div>
                </div>
                <div class="description1 flipInX" @click="sendRedbag">立即领取</div>
                <div class="description2" style="text-align:left; color:#fff; font-size: 12px;">备注：红包领取只有一次机会，关闭页面后不能领取</div>
            </div>
        </div>
</div>
        </van-overlay>
	</div>
</template>
<script>
import '@/assets/css/redbag.css'

import { getRedbagInfo, sendRedbag } from '@/api/user'
import { login } from '@/api/auth'
import {getRedbagUrl, getIndexUrl} from '@/utils/app'

export default {
    data() {
        return {
            info: this.$store.state.acc,
            user: this.$store.state.user,
            rebbag_user: this.$store.state.rebbag_user,
            list: [],
            total_amount: '-',
            show: false
        }
    },
    created(e) {
    	if(!this.rebbag_user.openid) {
        console.log(getRedbagUrl(this.info.code))
        // return
        login({qq: 'rebbag',redirect: getRedbagUrl(this.info.code)}).then(res=>{
          window.location.href = res
          console.log(res)
        })
      }else {
        this.getInfo()
      }
    },
    methods: {
    	getInfo (){
    		this.$toast.loading({
		      message: '加载中...',
		      forbidClick: false,
		      loadingType: 'spinner',
		      duration: 10000
		    });
    		getRedbagInfo({}).then(res=> {
    			this.$toast.clear()
          if(res > 0) {
            this.total_amount = res
            this.show = true
          }else{
            this.$dialog.alert({
              message: '对不起，非法请求',
            }).then((res) => {
              window.location.href = getIndexUrl(this.info.code)
            })
          }
    		})
    	},
      sendRedbag() {
        sendRedbag({qq: 'rebbag'}).then(res=>{
          this.$dialog.alert({
              message: res.msg,
          }).then((res) => {
              window.location.href = getIndexUrl(this.info.code)
          })
        })
      }
    }
}
</script>